package com.xiaobai.netease_news.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Android Studio
 * Project: NeteaseNews
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/4
 */
public class Header {
    private String template;
    private boolean hasCover;
    private int hasHead;
    private String skipId;
    private int replyCount;
    private String alias;
    private int hasImg;
    private String digest;
    private boolean hasIcon;
    private String skipType;
    private String cid;
    private String docid;
    private String title;
    private int hasAd;
    private int order;
    private List<ImgExtra> imgExtras;
    private int priority;
    private String lmodify;
    private String ename;
    private String tname;
    private String imgsrc;
    private String photosetId;
    private String ptime;
    private String subtitle;
    private String source;
    private String url;
    private String url_3w;
    private int votecount;
    private String boardId;

    public String getTemplate() {
        return template;
    }

    public boolean isHasCover() {
        return hasCover;
    }

    public int getHasHead() {
        return hasHead;
    }

    public String getSkipId() {
        return skipId;
    }

    public int getReplyCount() {
        return replyCount;
    }

    public String getAlias() {
        return alias;
    }

    public int getHasImg() {
        return hasImg;
    }

    public String getDigest() {
        return digest;
    }

    public boolean isHasIcon() {
        return hasIcon;
    }

    public String getSkipType() {
        return skipType;
    }

    public String getCid() {
        return cid;
    }

    public String getDocid() {
        return docid;
    }

    public String getTitle() {
        return title;
    }

    public int getHasAd() {
        return hasAd;
    }

    public int getOrder() {
        return order;
    }

    public List<ImgExtra> getImgExtras() {
        return imgExtras;
    }

    public int getPriority() {
        return priority;
    }

    public String getLmodify() {
        return lmodify;
    }

    public String getEname() {
        return ename;
    }

    public String getTname() {
        return tname;
    }

    public String getImgsrc() {
        return imgsrc;
    }

    public String getPhotosetId() {
        return photosetId;
    }

    public String getPtime() {
        return ptime;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public String getSource() {
        return source;
    }

    public String getUrl() {
        return url;
    }

    public String getUrl_3w() {
        return url_3w;
    }

    public int getVotecount() {
        return votecount;
    }

    public String getBoardId() {
        return boardId;
    }

    public void parseJson(JSONObject jsonObject) {
        if (jsonObject != null) {
            try {
                template = jsonObject.getString("template");
                hasCover = jsonObject.getBoolean("hasCover");
                hasHead = jsonObject.getInt("hasHead");
                skipId = jsonObject.optString("skipID");
                replyCount = jsonObject.getInt("replyCount");
                alias = jsonObject.getString("alias");
                hasImg = jsonObject.getInt("hasImg");
                digest = jsonObject.getString("digest");
                hasIcon = jsonObject.getBoolean("hasIcon");
                skipType = jsonObject.optString("skipType");
                cid = jsonObject.getString("cid");
                docid = jsonObject.getString("docid");
                title = jsonObject.getString("title");
                hasAd = jsonObject.getInt("hasAD");
                order = jsonObject.getInt("order");

                JSONArray imgextra = jsonObject.optJSONArray("imgextra");
                if (imgextra != null) {
                    imgExtras = new ArrayList<>();
                    for (int i = 0; i < imgextra.length(); i++) {
                        ImgExtra imgExtra = new ImgExtra();
                        JSONObject object = imgextra.getJSONObject(i);
                        imgExtra.parseJson(object);
                        imgExtras.add(imgExtra);
                    }
                }

                priority = jsonObject.getInt("priority");
                lmodify = jsonObject.getString("lmodify");
                ename = jsonObject.getString("ename");
                tname = jsonObject.getString("tname");
                imgsrc = jsonObject.getString("imgsrc");
                photosetId = jsonObject.optString("photosetID");
                ptime = jsonObject.getString("ptime");
                subtitle = jsonObject.optString("subtitle");
                source = jsonObject.optString("source");
                url = jsonObject.optString("url");
                url_3w = jsonObject.optString("url_3w");
                votecount = jsonObject.optInt("votecount");
                boardId = jsonObject.optString("boardid");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
